package com.geeksaga.dao.ibatis.mysql;

import java.util.List;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.geeksaga.common.util.DateConvertor;
import com.geeksaga.dao.SpecQueryDao;
import com.geeksaga.dao.ibatis.BaseIBatisDao;
import com.geeksaga.domain.Spec;
import com.geeksaga.domain.SpecQuery;

/**
 * @author newbie
 * @since 0.1
 */
@Repository
public class SpecQueryDaoImpl extends BaseIBatisDao implements SpecQueryDao {

    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#add(com.geeksaga.domain.SpecQuery)
     */
    public SpecQuery add(SpecQuery specQuery) throws DataAccessException {
        specQuery.setRegistDate(DateConvertor.getDateFormat());
        specQuery.setRegistTime(DateConvertor.getTimeFormat());
        specQuery.setRegistTimestamp(DateConvertor.getDateTimeFormat());
        specQuery.setModifyDate(DateConvertor.getDateFormat());
        specQuery.setModifyTime(DateConvertor.getTimeFormat());
        specQuery.setModifyTimestamp(DateConvertor.getDateTimeFormat());
        
        return (SpecQuery) getSqlMapClientTemplate().insert("SPEC_QUERY.add", specQuery);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#find(com.geeksaga.domain.SpecQuery)
     */
    public SpecQuery find(SpecQuery specQuery) throws DataAccessException {
        return (SpecQuery) getSqlMapClientTemplate().queryForObject("SPEC_QUERY.find", specQuery);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#findListBySpec(com.geeksaga.domain.Spec)
     */
    @SuppressWarnings("unchecked")
    public List<SpecQuery> findListBySpec(Spec spec) throws DataAccessException {
        return (List<SpecQuery>) getSqlMapClientTemplate().queryForList("SPEC_QUERY.findListBySpec", spec);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#modify(com.geeksaga.domain.SpecQuery)
     */
    public int modify(SpecQuery specQuery) throws DataAccessException {
        specQuery.setModifyDate(DateConvertor.getDateFormat());
        specQuery.setModifyTime(DateConvertor.getTimeFormat());
        specQuery.setModifyTimestamp(DateConvertor.getDateTimeFormat());
        
        return getSqlMapClientTemplate().update("SPEC_QUERY.update", specQuery);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#confirmPassword(com.geeksaga.domain.SpecQuery)
     */
    public SpecQuery confirmPassword(SpecQuery specQuery) throws DataAccessException {
        return (SpecQuery) getSqlMapClientTemplate().queryForObject("SPEC_QUERY.confirmPassword", specQuery);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#remove(com.geeksaga.domain.SpecQuery)
     */
    public int remove(SpecQuery specQuery) throws DataAccessException {
        return getSqlMapClientTemplate().delete("SPEC_QUERY.remove", specQuery);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.dao.SpecQueryDao#updateDelYn(com.geeksaga.domain.SpecQuery)
     */
    public int updateDelYn(SpecQuery specQuery) throws DataAccessException {
        return getSqlMapClientTemplate().update("SPEC_QUERY.updateDelYn", specQuery);
    }
}